package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-03-12 17:08
 */
public class QLint512 {
    public int numDecodings(String s) {
        if(s == null || s.length() == 0 || s.startsWith("0")) {
            return 0;
        }

        int n = s.length();
        int[] dp = new int[n + 1];
        dp[0] = 1;
        dp[1] = 1;

        for (int i = 2; i <= n; i++) {
            if(s.charAt(i - 1) != '0') {
                dp[i] += dp[i - 1];
            }

            int num = (s.charAt(i - 2) - '0') * 10 + s.charAt(i - 1) - '0';
            if(num >= 10 && num <= 26) {
                dp[i] += dp[i - 2];
            }
        }

        return dp[n];
    }
}
